/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mantechhelpdesk.entity;

import java.io.Serializable;
import java.util.Date;
import mantechhelpdesk.dao.DbConnection;
import mantechhelpdesk.dao.DepartmentsDao;
import mantechhelpdesk.dao.RolesDao;

/**
 *
 * @author DinhThang
 */
public class Users implements Cloneable, Serializable {

    /**
     * Persistent Instance variables. This data is directly mapped to the
     * columns of database table.
     */
    private int userID;
    private Integer roleID;
    private String roleName;
    private Integer departmentID;
    private String departmentName;
    private String username;
    private String password;
    private String firstName;
    private String lastName;
    private Date createTime;
    private boolean isEnable;

    /**
     * Constructors. DaoGen generates two constructors by default. The first one
     * takes no arguments and provides the most simple way to create object
     * instance. The another one takes one argument, which is the primary key of
     * the corresponding table.
     */
    public Users() {
    }

    public Users(int UserIDIn) {

        this.userID = UserIDIn;

    }

    /**
     * Get- and Set-methods for persistent variables. The default behaviour does
     * not make any checks against malformed data, so these might require some
     * manual additions.
     */
    public int getUserID() {
        return this.userID;
    }

    public void setUserID(int UserIDIn) {
        this.userID = UserIDIn;
    }

    public Integer getRoleID() {
        return this.roleID;
    }

    public String getRoleName() {
        return roleName;
    }

    public void setRoleName(String roleName) {
        this.roleName = roleName;
    }

    public String getDepartmentName() {
        return departmentName;
    }

    public void setDepartmentName(String departmentName) {
        this.departmentName = departmentName;
    }
    
    public void setRoleID(Integer RoleIDIn) {
        try {
            RolesDao rolesDao = new RolesDao();
            Roles role = rolesDao.getObject(DbConnection.getConnection(), RoleIDIn);
            if (null != role && role.getRoleName().length() > 0) {
                roleName = role.getRoleName();
            }
            this.roleID = RoleIDIn;
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    public Integer getDepartmentID() {
        return this.departmentID;
    }

    public void setDepartmentID(Integer DepartmentIDIn) {
        try {
            DepartmentsDao departmentsDao = new DepartmentsDao();
            Departments depart = departmentsDao.getObject(DbConnection.getConnection(), DepartmentIDIn);
            if (null != depart && depart.getDepartmentName().length() > 0) {
                departmentName = depart.getDepartmentName();
            }
            this.departmentID = DepartmentIDIn;
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    public String getUsername() {
        return this.username;
    }

    public void setUsername(String UsernameIn) {
        this.username = UsernameIn;
    }

    public String getPassword() {
        return this.password;
    }

    public void setPassword(String PasswordIn) {
        this.password = PasswordIn;
    }

    public String getFirstName() {
        return this.firstName;
    }

    public void setFirstName(String FirstNameIn) {
        this.firstName = FirstNameIn;
    }

    public String getLastName() {
        return this.lastName;
    }

    public void setLastName(String LastNameIn) {
        this.lastName = LastNameIn;
    }

    public Date getCreateTime() {
        return this.createTime;
    }

    public void setCreateTime(Date CreateTimeIn) {
        this.createTime = CreateTimeIn;
    }

    public boolean getIsEnable() {
        return this.isEnable;
    }

    public void setIsEnable(boolean IsEnableIn) {
        this.isEnable = IsEnableIn;
    }

    /**
     * setAll allows to set all persistent variables in one method call. This is
     * useful, when all data is available and it is needed to set the initial
     * state of this object. Note that this method will directly modify instance
     * variales, without going trough the individual set-methods.
     */
    public void setAll(int UserIDIn,
            int RoleIDIn,
            int DepartmentIDIn,
            String UsernameIn,
            String PasswordIn,
            String FirstNameIn,
            String LastNameIn,
            java.sql.Date CreateTimeIn,
            boolean IsEnableIn) {
        this.userID = UserIDIn;
        this.roleID = RoleIDIn;
        this.departmentID = DepartmentIDIn;
        this.username = UsernameIn;
        this.password = PasswordIn;
        this.firstName = FirstNameIn;
        this.lastName = LastNameIn;
        this.createTime = CreateTimeIn;
        this.isEnable = IsEnableIn;
    }

    public Users(int UserIDIn,
            Integer RoleIDIn,
            Integer DepartmentIDIn,
            String UsernameIn,
            String PasswordIn,
            String FirstNameIn,
            String LastNameIn,
            java.sql.Date CreateTimeIn,
            boolean IsEnableIn) {
        this.userID = UserIDIn;
        this.roleID = RoleIDIn;
        this.departmentID = DepartmentIDIn;
        this.username = UsernameIn;
        this.password = PasswordIn;
        this.firstName = FirstNameIn;
        this.lastName = LastNameIn;
        this.createTime = CreateTimeIn;
        this.isEnable = IsEnableIn;
    }
}
